/**
 * KopsoxFramework
 * Copyright (C) 2010 Free Software Foundation, Inc. <http://fsf.org/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kopsox.data.impl;

import java.math.BigDecimal;
import java.util.Date;

import org.kopsox.data.ValueDescriptor;
import org.kopsox.environment.proxy.KopsoxRegistry;
import org.kopsox.general.priority.LoggingPriorityEnum;
import org.kopsox.util.log.KopsoxLogger;

/**
 * This thread creates 4 (String,Integer,Date,BigDecimal) different Polymorph an changes it x-Times
 * 
 * @author Konrad Renner - 26.11.2010
 *
 */
public class PolymorphCreatingThread extends Thread {
	public static final KopsoxLogger LOGGER = KopsoxRegistry.INSTANCE.getKopsoxLoggerForClass(PolymorphCreatingThread.class);
	private final int numberOfChanges;
	private final int threadNumer;
	
	public PolymorphCreatingThread(int threadNumer,int numberOfChanges) {
		this.threadNumer = threadNumer;
		this.numberOfChanges = numberOfChanges;
	}

	/* (non-Javadoc)
	 * @see java.lang.Thread#run()
	 */
	@SuppressWarnings("boxing")
	@Override
	public void run() {
		long time = LOGGER.startLog("Erstellung, Thread:"+threadNumer, LoggingPriorityEnum.DEBUG.getPriority());
		
		ValueDescriptor desc = new ValueDescriptorImpl.ValueDescriptorBuilder().isAutoValidationEnabled(true).isNullable(false).build();
		Polymorph<Integer> intPolymorph = new Polymorph<Integer>(1,desc);
		Polymorph<Date> datePolymorph = new Polymorph<Date>(new Date(System.currentTimeMillis()),desc);
		Polymorph<String> stringPolymorph = new Polymorph<String>("oNe",desc);
		Polymorph<BigDecimal> bdecPolymorph = new Polymorph<BigDecimal>(new BigDecimal("1.00"),desc);
		
		LOGGER.endLog("Erstellung, Thread:"+threadNumer, LoggingPriorityEnum.DEBUG.getPriority(),time);
		
		for(int i=0;i<numberOfChanges;i++) {
			time = LOGGER.startLog("Aenderungsdurchlauf, Thread:"+threadNumer, LoggingPriorityEnum.DEBUG.getPriority());
			
			intPolymorph = intPolymorph.changeValue(i);
			datePolymorph = datePolymorph.changeValue(new Date(System.currentTimeMillis()));
			stringPolymorph = stringPolymorph.changeValue("The new number will be concated to this little string:"+i);
			bdecPolymorph = bdecPolymorph.changeValueWithString(i+".25");
			
			LOGGER.endLog("Aenderungsdurchlauf, Thread:"+threadNumer, LoggingPriorityEnum.DEBUG.getPriority(),time);
		}
		
	}
}
